package org.dwell.urlfilter.demo.test;

import org.dwell.urlfilter.demo.domain.CoreRole;
import org.dwell.urlfilter.demo.domain.CoreUserRole;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Jange on 2016/4/6.
 */
public class CoreUserRoleDB {
    private static List<CoreUserRole> userRoleList = new ArrayList<CoreUserRole>();

    static {
        userRoleList.add(new CoreUserRole("user000000001", "role000000001"));
        userRoleList.add(new CoreUserRole("user000000002", "role000000002"));
        userRoleList.add(new CoreUserRole("user000000003", "role000000003"));
        userRoleList.add(new CoreUserRole("user000000004", "role000000004"));
        userRoleList.add(new CoreUserRole("user000000005", "role000000005"));
    }

    public static List<CoreRole> listByUserId(String userId) {
        List<CoreRole> result = new ArrayList<CoreRole>();
        CoreRole coreRole = null;
        for (CoreUserRole userRole : userRoleList) {
            if(userRole.getUserId().equalsIgnoreCase(userId)) {
                coreRole = CoreRoleDB.getByRoleId(userRole.getRoleId());

                if(null != coreRole) {
                    result.add(coreRole);
                }
            }
        }

        return result;
    }
}
